home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / GSBug / GSBug.Tutorial < prev    next >
Encoding:
Text File  |  1991-08-27  |  29.7 KB  |  617 lines  |  [TEXT/pdos]

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                              GSBug is Your Friend
  10.                            (a quick intro to GSBug)
  11.                                     v.1.2
  12.                                by:  Tim Swihart
  13.  
  14.  
  15.  
  16. So, you just got GSBug installed for the first time and don't have a clue how
  17. to use it.  Sure, you could call APDA (1-800-282-2732) and order the complete
  18. package (part #A0037LL/A, price $30), but you're not sure if GSBug will really
  19. help you find those nasty bugs in the Apple IIGS software you're developing.
  20. Well, from the next paragraph until the end of this file, I'll present a quick
  21. introduction to some of the reasons why GSBug is a "MUST HAVE" tool for all
  22. IIGS developers.  It doesn't matter what language you program in, or which
  23. environment you use, GSBug is the key to tracking down and exterminating those
  24. nasty bugs that make your software look shabby.
  25.  
  26. The version of GSBug that APDA currently stocks is older than the version found
  27. on the disk containing this tutorial.  So why buy APDA's version?  To get the
  28. full manual - it's well worth the thirty bucks they're asking!
  29.  
  30.  
  31. Installation:
  32.  
  33. Before we can really get into it, you need to install GSBug and the
  34. GSBug.Templates file and reboot your IIGS.  If you only have one computer,
  35. then print this file and continue reading from the printout.  GSBug is an INIT
  36. with the file name "GSBug.INIT" - install it by copying this file into your
  37. boot disk's SYSTEM/SYSTEM.SETUP folder.  Copy the "GSBug.Templates" file into
  38. the same folder.
  39.  
  40. Over the course of time, the name used for the GSBug init file has changed
  41. slightly.  To be certain you don't accidently install two (or more) copies
  42. of GSBug, carefully examine the contents of your boot disk's
  43. System/System.Setup folder.  If you see more than one file with a name
  44. similar to "GSBug.init" (such as "debug.init" or "GSBug1.5B11init") then
  45. take out all but the most recent one.  Having more than one copy of GSBug
  46. installed tends to cause problems (such as crashes during booting).
  47.  
  48.  
  49. Care & Feeding of GSBug:
  50.  
  51. Now that everything is installed, reboot your computer.  No need to launch any
  52. particular application just yet, I have to explain the various parts of
  53. GSBug's screen and I want to cover a few basic GSBug commands before we go bug
  54. hunting.  I'll assume you're running the Finder right now, but it really
  55. doesn't matter a whole lot what application is running, as long as it is a
  56. 16-bit application (i.e.:  a true IIGS desktop application).
  57.  
  58. You can pop into GSBug at any time (assuming interrupts aren't disabled) by
  59. pressing OPEN APPLE-OPTION-CONTROL-ESC  (if you're having troubles remembering
  60. all of those keys at once, just think of it as the same keys that you use to
  61. get to the built-in control panel plus the OPTION key).  You'll be presented
  62. with a rather busy-looking 80-column text screen.  (there's a screen dump
  63. right below this paragraph - I told you it was busy-looking screen)
  64.  
  65.  
  66. ------ cut here to start the screen dump ------
  67.  
  68. KEY BRK  DebugD  K/PC   B   D    S    A    X    Y    M   Q   L  P  nvmxdizc e d
  69. 00  o d   9500  FD/688D FD 2500 1FE0 0000 4D95 0044  0C  BE  1  03 00000011 0 0
  70.  
  71. 1FF2:60  00/0000:  BE '>'  00/0000-00-00
  72. 1FF1:43  00/0000:  BE '>'  00/0000-00-00
  73. 1FF0:FE  00/0000:  BE '>'  00/0000-00-00
  74. 1FEF:01  00/0000:  BE '>'  00/0000-00-00
  75. 1FEE:37  00/0000:  BE '>'  00/0000-00-00
  76. 1FED:0C  00/0000:  BE '>'  00/0000-00-00
  77. 1FEC:00  00/0000:  BE '>'  00/0000-00-00
  78. 1FEB:4D  00/0000:  BE '>'  00/0000-00-00
  79. 1FEA:7A  00/0000:  BE '>'  00/0000-00-00
  80. 1FE9:C0  00/0000:  BE '>'
  81. 1FE8:00  00/0000:  BE '>'  E1/0000.000F-T
  82. 1FE7:2C  00/0000:  BE '>'  00/0000.0000-?
  83. 1FE6:00  00/0000:  BE '>'  00/0000.0000-?
  84. 1FE5:E0  00/0000:  BE '>'  00/0000.0000-?
  85. 1FE4:6A  00/0000:  BE '>'  00/0000.0000-?
  86. 1FE3:B4  00/0000:  BE '>'  00/0000.0000-?
  87. 1FE2:62  00/0000:  BE '>'  00/0000.0000-?
  88. 1FE1:DA  00/0000:  BE '>'  00/0000.0000-?
  89. 1FE0:FD  00/0000:  BE '>'  00/0000.0000-?
  90.  
  91. :GSBug V1.5b9 w/Glue Support -(C)1986-90 Apple Computer,Inc.
  92.  
  93. ------ cut here to end the screen dump ------
  94.  
  95.  
  96. Top Two Lines:
  97.  
  98. The first two lines of the screen show the contents of various registers.  The
  99. top line of the screen starts off with "KEY  BRK  DebugD" - those are headings
  100. for the items in the second line of the screen.  The meanings of those
  101. headings (and the items under them) are:
  102.  
  103. Heading     Meaning
  104. -------     -------------------------------------------
  105. KEY         Modifiers used to separate debugger keys from application keys
  106. BRK         (beyond the scope of this quick intro - see the manual)
  107.  
  108. DebugD      Debugger's direct page (1K in size) - in bank $00
  109. K/PC        K=program bank, PC=program counter 
  110.  
  111. B           app's data bank
  112. D           current direct page in bank zero 
  113.  
  114. S           current stack pointer
  115. A           accumulator's value
  116.  
  117. X           X register's value
  118. Y           Y register's value
  119.  
  120. M           machine state register's value
  121. Q           quagmire register's value
  122.  
  123. L           Language card bank
  124. P           processor-status register's value
  125.  
  126. nvmxdizc    bits that make up "P" (n=negative, c=carry, etc)
  127. e           emulation mode flag
  128. d           disassembly mode flag (0=recognize SEP & REP during "L"isting)
  129.  
  130.  
  131. If you want more information on a specific register's meaning then look it up
  132. in the IIGS Hardware reference manual, the GSBug manual, or any good book that
  133. covers the IIGS's internal hardware.  Any of these register's values can be
  134. changed - we'll show how to do that in a few paragraphs or so...
  135.  
  136.  
  137. The Left-Hand Side:
  138.  
  139. The next major area of the screen is the 4-digit column of numbers running
  140. down the far left side.  There is a colon on each line after the fourth
  141. digit, and then there is a column (two digits wide) of numbers.  All of these
  142. numbers are in hex and this area is the stack.  The four digit column, the
  143. colons, and the two digit column are collectively known as the "stack
  144. subdisplay area" - remember that, there's a test at the end of this file.
  145. The column on the left of the colon is the address of the stack and the
  146. column on the right (the two digit column) are the values on the stack.
  147. The bottom-most four digit stack address is the "top" of the stack (i.e.:
  148. if your app pushes anything on the stack, that's the address it would wind
  149. up at).  As you step through your application (we'll show how in a minute,
  150. patience...) the stack will scroll upwards as things are pushed onto it and
  151. downwards as things are pulled off of it.
  152.  
  153.  
  154. The Not-So-Left-Hand Side:
  155.  
  156. The next major area should be a column of "00/0000:  BE '>'" known as the
  157. "RAM subdisplay area".  This area is used to display any 19 memory locations
  158. that you want to keep an eye on.  The value at each of those locations is
  159. shown in hex (that's what the "BE" means - location 00/0000 contains hex "BE"
  160. when I wrote this) and in ASCII (the ASCII version is between the single quote
  161. marks, i.e.:  the "'>'").  It is possible to have this subdisplay show a
  162. two-byte or a three-byte value instead of the one-byte value.  You lose the
  163. ASCII display if you opt for the 2 or 3 byte values.
  164.  
  165. After I finish explaining the rest of the screen, I'll come back and describe
  166. how to change these 19 "windows on memory" to look at what you want to
  167. monitor.
  168.  
  169.  
  170. The Center Part:
  171.  
  172. The next major area of the screen is the 9 lines of "00/0000-00-00", better
  173. known as the "Breakpoint subdisplay" (they're on the top half of the screen).
  174. GSBug lets you set up to 17 breakpoints in your program (not counting BRK
  175. instructions you imbed in your program yourself).  Curious about how you set
  176. 17 break points when there are only 9 lines in this section?  Did I mention
  177. that APDA stocks the manual (which has full details)? <grin>  Seriously, you
  178. can "extend" the breakpoint subdisplay by shrinking the section under it
  179. (which we haven't described yet).  For the purposes of this quick intro, I'm
  180. not going to show how to do this (you need some kind of reason to get the
  181. manual).  I'll just describe this area and later show how to set up to 9 break
  182. points.
  183.  
  184. The "00/0000" part of the breakpoint subdisplay is obviously an address - in
  185. fact, it's the address you want to break on.  The next part "-00-" is the
  186. trigger value.  GSBug is smart enough to count how many times an address has
  187. been executed and break on a certain number (i.e.:  put a "03" here and GSBug
  188. will break the third time that address is executed).  The last part of this
  189. area is the running count - this is how GSBug lets you know how many times
  190. that area has been executed (rather than leave you wondering, it tells you and
  191. you can be ready for the break).  You set the address and trigger portions and
  192. GSBug sets the count portion.
  193.  
  194.  
  195. The Bottom Part of the Center Part:
  196.  
  197. The bottom half of the center of the screen is known as the "Memory
  198. Protection Subdisplay" and starts off with "E1/0000.000F-T".  This area can
  199. be expanded (or shrunk) by trading lines of this area for lines of the one
  200. above it (the "Breakpoint subdisplay").  If you want to know how to do this,
  201. read the manual from APDA, it's big (roughly 150 pages) and I'm not
  202. retyping all of it here!  <grin>
  203.  
  204. The "E1/0000.000F" is the address range starting at E1/0000 and ending at
  205. E1/000F.  The "T" at the end means that this range of memory is protected from
  206. code tracing.  If you're tracing through your code and it jumps (JSR's, JSL's,
  207. whatever) into this range of memory, then the code in this range will NOT be
  208. traced - it will be executed at full speed instead.
  209.  
  210. There are two other options for code protection ("W" and "H").  They are
  211. beyond the scope of this quick tutorial (I'm only trying to cover the
  212. basics here).
  213.  
  214.  
  215. Where You Type Commands:
  216.  
  217. The bottom line on the screen is the command line subdisplay (catchy name,
  218. eh?).  When you first enter GSBug, this line will contain the copyright
  219. message and version number for GSBug (unless you've used the DebugStr or
  220. SetMileStone "tool" calls to change this string).  As soon as you press a
  221. key, the copyright message vanishes and your keypress shows up next to the
  222. blinking cursor.  This is where you'll type various commands to make GSBug
  223. help you get the kinks out of your software.
  224.  
  225.  
  226. What's the Big Blank Spot For?:
  227.  
  228. The big blank area towards the far right of the screen is officially known as
  229. the "disassembly subdisplay" (it's one of the big reasons you're using GSBug -
  230. even if you don't know it yet).  As you single-step through your software,
  231. trace through it, or just list areas of memory this area will show you the
  232. disassembled version of your program.  One of the really slick things about
  233. this area is that it's smart enough to know about the names of GS/OS calls and
  234. Toolbox calls - so you see things like "_CheckUpdate" instead of "JSL E10000".
  235. That makes if VERY easy to line up pieces of your source with the disassembly
  236. if you're working in a high-level language.  It also makes it a LOT easier to
  237. see what you're doing!
  238.  
  239. GSBug also knows about the alternate Toolbox entry point (E10004) and will
  240. display those as tool calls also.  The leading underscore ("_") lets you know
  241. that GSBug is substituting the tool's name for you.  If the tool call is being
  242. made through "glue", then the underscore is preceded by an asterisk ("*").
  243.  
  244. If you've ever used the built in "monitor" (I'm not talking about your RGB
  245. monitor, I'm talking about the disassembler that's been built into Apple II's
  246. for a LONGGGGGGG time now), then you'll be able to quickly figure out that
  247. the left-most part of the disassembly subdisplay is the address, the inside
  248. columns are the hex bytes making up the code about to be disassembled, and the
  249. right-most part is the disassembled version of your software.
  250.  
  251.  
  252. Your First GSBug Command:
  253.  
  254. OK, you now know what all of the various areas of this rather busy-looking
  255. screen are for, so let's get down to business!  The first thing to do is press
  256. the "L" key (upper or lower case work the same these days) and then press
  257. RETURN.  This will fill the disassembly subdisplay with 19 lines of
  258. disassembled code (which 19 lines were disassembled really doesn't matter).
  259. Study it until you can tell at a glance which parts are the address, which
  260. parts are the hex bytes, and which parts are the disassembled code.
  261.  
  262. Type "L" and press RETURN again - you get the next 19 lines of memory (see,
  263. I told you it was a lot like the built-in monitor).
  264.  
  265. Now, let's do something a tad more useful...  Press the "S" key and RETURN
  266. (you just told GSBug to start single-stepping through your application).  Be
  267. careful what keys you press while in the single step mode - lots of
  268. weird-looking things can happen (they're all normal, but if you don't expect
  269. them you can get confused).  For now, ONLY press the keys this tutorial tells
  270. you to.  If you can't wait and just HAVE to bang on all of the various keys,
  271. then go ahead - reboot once you've totally confused yourself, pop back into
  272. GSBug and catch up with the rest of the folks reading this.
  273.  
  274. To tell GSBug to execute the highlighted instruction, press the SPACE BAR one
  275. time.  Heck, press it several times so that you get a bunch of lines of
  276. disassembled code on the screen.  Notice that the code scrolls up and the
  277. "highlighted" area stays in the same place?  Notice it's kind of close to the
  278. bottom of the screen?  Later I'll tell you how to move it up higher.
  279.  
  280. Press the ESC key.  That takes you out of single-step and returns you to the
  281. command line.  Press "S" and RETURN again to restart single stepping.  Notice
  282. that the lines ABOVE the highlighted area have been erased?  Remember that -
  283. if you halt single-stepping and need some piece of info above the highlighted
  284. area, then write it down because it'll be wiped out when you restart
  285. single-stepping (or when you do any of a bunch of different things).  If you
  286. have your printer connected to slot 1, then you can print GSBug's screen using
  287. the "P" command (press "P" and RETURN - be sure you're NOT single-stepping
  288. when you do this, "P" only prints from the command line).
  289.  
  290.  
  291. Lock a Tractor Beam onto Them...:
  292.  
  293. Want an easy way to have the computer step through source for you without
  294. having to bang again and again on the SPACE BAR?  Start single-stepping
  295. ("S" and RETURN), then press RETURN again.  VRRRROOOOMMMMMM!  Can't read all
  296. the stuff flying by?  No sweat, press SPACE BAR and you'll be back to
  297. single-stepping.  Pressing the RETURN key a second time kicked GSBug into
  298. "Trace" mode.
  299.  
  300. Trace actually has two speeds, the default is fast (we like to test
  301. developers' speed reading skills).  To kick TRACE into low gear, press the
  302. left arrow key.  If you're in single-step mode, then you won't see the speed
  303. change (after all, it affects TRACE, not SINGLE-STEP), but fear not brave
  304. developer, the speed change has been made.  Press RETURN again (to be sure
  305. you're in TRACE mode) and press the left arrow key (if you didn't a few lines
  306. ago) to kick TRACE into low gear.  Want to get back into high gear?  Press the
  307. right arrow key (sneaky, eh?).
  308.  
  309.  
  310. RED ALERT!:
  311.  
  312. Do _NOT_ press the down arrow key while TRACING or single-stepping (unless
  313. you know what you're doing).  The down arrow key tells GSBug to SKIP the
  314. highlighted instruction!  This is a great way to step over BRK instructions,
  315. but it's not a real smart thing to do at random while TRACING through an
  316. application (randomly skipping an instruction generally results in a crash).
  317.  
  318.  
  319. Move That Line Up:
  320.  
  321. If you want to raise the highlighted line within the disassembly subdisplay,
  322. then press ESC (to get back to the command line) and type "SET"  (don't type
  323. the quotes, ok?) and press RETURN.  The up and down arrows now control the
  324. vertical position of the highlighted bar within the disassembly subdisplay.
  325. Position the bar where you want it and press ESC.  That position will be
  326. remembered until the next time you move it or until you reboot (then it goes
  327. back to the default position).  The manual for GSBug tells you how to save
  328. this new position to a configuration file (it also tells you that pressing the
  329. left and right arrow will move the stack subdisplay up and down, and that
  330. pressing a number less than eight will change the slot used to print the
  331. screen).
  332.  
  333.  
  334. Reaching the Breaking Point:
  335.  
  336. Alright, time for some fancy stuff!  The next couple of sections will assume
  337. you were running the IIGS Finder when you popped into GSBug (other apps will
  338. work just fine, but why be difficult?).  GSBug will let you break on any tool
  339. call (or calls) that you specify, so let's set a few tool breaks and learn how
  340. to use this feature.
  341.  
  342. From GSBug's command line (press ESC if you're still stepping or tracing),
  343. type "settbrk _sysbeep" and press RETURN.  If GSBug beeps at you instead of
  344. accepting this line, then you didn't type it right (there are two t's in
  345. "settbrk" and don't type the quotes).  Type "settbrk #090E" and press RETURN.
  346. You just added two tool calls to GSBug's list of tools to break on.  The first
  347. one was added by naming the tool to break on ("_sysbeep") and the second one
  348. was added by specifying the tool's number ("#090E").  This lets you set tool
  349. breaks regardless of whether you know the tool's name or number.
  350.  
  351. Type "showbrks" and press RETURN to see the complete list of tool breaks that
  352. GSBug has been told about.  Notice that the left hand side of the screen now
  353. implies that you can set breaks on GS/OS calls?  That's because you can!
  354. GS/OS breaks have to be set by number (not by name).
  355.  
  356. All we've done so far is make a list of tools for GSBug to break on.  We
  357. haven't actually told GSBug to break on them, that requires a separate
  358. command.  Type "tbrkin" to tell GSBug to break on all of the tool calls in
  359. its list.  Now, when either a call to SysBeep or a call to NewWindow
  360. (tool $090E is NewWindow) is made, we'll be dropped back into GSBug.
  361.  
  362.  
  363. Oh Yeah?  Prove It!:
  364.  
  365. Make sure you're at GSBug's command line (press ESC if you aren't).  Type "R"
  366. and RETURN.  This resumes full execution of your application.  To test the
  367. tool breaks we just set, we need to force the Finder (or whatever app you
  368. stubborn folks decided to use instead of the Finder) to make a call to
  369. NewWindow and/or to SysBeep.  Double click on a disk icon, get info on a file,
  370. open a folder, open a desk accessory, etc to get the Finder to open a new
  371. window.  Notice that you land in GSBug?
  372.  
  373. Press "S" and RETURN to enter single-stepping.  Notice that the highlighted
  374. instruction is "NewWindow".  Ah, the tool break works.  Now, press SPACE BAR
  375. to execute the NewWindow call, press ESC to stop single-stepping, and type "R"
  376. and RETURN to resume running the Finder.  (if we didn't bother to single step
  377. across the NewWindow call, we would just fall right back into the debugger
  378. since we have a break point set on that call).
  379.  
  380.  
  381. Take it Out, Wise Guy!;
  382.  
  383. Tired of falling into GSBug everything a new window is opened?  There are
  384. several ways to remove tool breaks.  The easiest way is to type "tbrkout" to
  385. stop breaking on the listed tool calls without trashing the list.  Typing
  386. "tbrkin" makes GSBug start breaking on them again.
  387.  
  388. To clear the list of tool breaks, either type "clrtbrk _sysbeep" (to remove
  389. the sysbeep break we put in earlier) and repeat that for "_newwindow" or wipe
  390. the all out with "clralltbrks".  I'll let you decide...
  391.  
  392.  
  393. Cheap Trick #1:
  394.  
  395. Being able to break into the debugger based on a tool call is VERY handy!  But
  396. what if you want to see the stack being set up BEFORE your code gets all the
  397. way down to the tool call itself?  After all, if you're not putting enough
  398. parameters on the stack (or too many), then breaking on the tool call itself
  399. is too late to watch the stack being built.  There's an easy solution for
  400. this - stick a SysBeep call in your source ABOVE the tool call you really
  401. want to break on and set a tool break on SysBeep.  This will let you
  402. single-step through the stack setup for the call you're really interested in.
  403. OK, so it's a cheap trick, but it's darned effective...
  404.  
  405. This trick was invented in the dark ages before DebugStr was part of GSBug
  406. (DebugStr is explained near the very end of this document and is a little
  407. trickier to use than Cheap Trick #1).
  408.  
  409.  
  410. I Don't Like My Registers:
  411.  
  412. Remember earlier when I mentioned that you can change the values of the
  413. various registers from within GSBug?  This lets you change values that are
  414. about to be pushed on the stack and do all kinds of neat things.  You're
  415. sharp, so I won't bore you with all the things this lets you do, I'll just
  416. cut right to the description of HOW to do it...
  417.  
  418. To change the accumulator's value, type "a=value" on the command line.
  419. Replace "value" with the hex value you want  to stuff into the accumulator.
  420. Type "x=value" to set the x register, "y=value" to set the y register, etc.
  421. You can't type "a=x" to set the accumulator to the value in the x register,
  422. but since you can see the x register's value, this isn't that big of a loss.
  423.  
  424.  
  425. Cheap Trick #2:
  426.  
  427. If you accidently SKIP an instruction that you didn't mean to (and you haven't
  428. executed any more since then), you can "unskip" it by exiting single-step
  429. mode, then type "pc=value" where "value" is the address (all three bytes just
  430. to be safe) that the skipped instruction is at.  Press RETURN and then resume
  431. single-stepping (notice that you're back at the skipped instruction now).
  432.  
  433. This tricks works because the "pc" register is the program counter (the thing
  434. that determines what address will have its instruction executed next).
  435.  
  436.  
  437. Cheap Trick #3:
  438.  
  439. Fudging the program counter (pc=value) will let you push extra info on the
  440. stack in cases where you didn't push enough for a call.  Be careful with
  441. this - you may need to set the accumulator before re-executing an
  442. already-executed PHA and you could totally trash the stack if you're not
  443. paying attention.  One place this is handy is to compensate for passing a
  444. WORD instead of a LONG (easy to do with C when you're dealing with resource
  445. ID's).  If you don't understand this trick, don't use it!
  446.  
  447. A minor modification on this stunt is (obviously) to pull extra bytes OFF of
  448. the stack in cases where you left something on there that shouldn't have been
  449. left on.  Once you spot problems like too much or too little data on the
  450. stack,  FIX YOUR SOURCE CODE AND RECOMPILE IT!!!!  You don't really want to
  451. have to find this bug a second time do you?
  452.  
  453.  
  454. Cheap Trick #4:
  455.  
  456. GSBug is a lot like the monitor in certain respects.  That means many of the
  457. commands you're used to from the monitor will work under GSBug.  Setting
  458. values in memory under GSBug is done just like it is under the monitor
  459. (i.e.:  address : value1 value2 value3 value4 ...).   addressT and RETURN
  460. starts tracing at the memory location specified by "address".  addressS and
  461. RETURN starts single-stepping at the memory location specified by "address".
  462. addressL and RETURN lists 19 lines of disassemby starting at the memory
  463. location specific by "address".  You can even use the built-in mini assembler
  464. if you want (type "asm" and RETURN).
  465.  
  466.  
  467. Peering Into Memory:
  468.  
  469. The 19 "windows on memory" can be used by typing "mem" and RETURN on the
  470. command line.  This puts the cursor on the far right of the first line in the
  471. RAM subdisplay area.  Type the address you want to watch and press RETURN.
  472. That will move you to the next line (so you can set the address for the second
  473. memory location).  If you want to see two bytes starting at that address,
  474. press "P".  To see three bytes, press "L".  "Z" toggles between direct-page
  475. and absolute addressing, ":" toggles between direct, 2-byte indirect, and
  476. 3-byte indirect addressing.  Press "?" for more info.
  477.  
  478. This provides a nice way to look at variables in memory, dereference
  479. pointers/handles, etc.  When the contents of any "peered into" location
  480. changes, the corresponding line on GSBug's screen will change also.
  481.  
  482.  
  483. Cheap Trick #5:
  484.  
  485. (this one's actually not cheap, it's pretty danged useful!)  While
  486. single-stepping or tracing, you can see other "screens" by pressing various
  487. keys (this accounts for the weird effects I alluded to earlier).  Press "S" to
  488. see the SHR screen (i.e.:  your desktop application's desktop), "D" to see the
  489. double hi-res screen, "T" to see the text screen, "8" to see 80-column
  490. display, "4" to see 40-column display, "H" to see the Hi-Res screen, "L" for
  491. the Lo-Res screen, and ESC to exit single-stepping.  This lets you see your
  492. application's screen instead of GSBug's screen (makes it a LOT easier to
  493. debug your apps when you can see their screens...).
  494.  
  495.  
  496. Study For The Test:
  497.  
  498. I told you earlier that there would be a test at the end of this tutorial, so
  499. now's your chance to kick back and study a bit.  So far, we've covered what
  500. the various parts of GSBug's screen mean, how to disassemble pieces of memory
  501. (using "L"), how to single-step and trace (at different speeds) through your
  502. application, how to set, use, and clear breakpoints, how to display various
  503. screens, and how to set up the RAM subdisplay area.
  504.  
  505.  
  506. Don't Touch That Dial!:
  507.  
  508. The material covered so far gives you a decent foundation to draw upon as you
  509. hunt bugs in your own software.  We've only lightly touched on what GSBug can
  510. really do (I'm not typing all 150 or so pages of the manual into this
  511. "introduction" to GSBug).  GSBug offers a lot of power and capabilities that
  512. should be learned by all developers.
  513.  
  514. Before I wrap up this tutorial I want to cover the use of templates and
  515. describe some of the new features in GSBug v.1.5b11 that aren't described in
  516. the APDA documentation (because we just added the features and haven't
  517. replaced APDA's master manual yet).
  518.  
  519.  
  520. Templates By Jim:
  521.  
  522. GSBug provides an easy way for you to view portions of memory through
  523. templates.  This allows you to "see" the data structures in memory just
  524. like they appear in the documentation (i.e.: see them divided into the
  525. various fields).  The GSBug.Templates file that you were supposed to
  526. have placed in the SYSTEM/SYSTEM.SETUP folder of your boot disk contains
  527. a complete set of templates for use with our interface files.  One of the
  528. Apple II Developer Technical Support Engineers put these templates together
  529. (and came up with a pretty neat way to build in a "help system" - so tell
  530. Jim "thanks" next time a template bails you out of a jam).
  531.  
  532. GSBug does NOT automatically load those templates unless you rename them (see the "GSBug.Specs" file for more information).  You have to tell GSBug to load
  533. them (and you can unload them later).  To load these templates, just type
  534. "loadtemp */system/system.setup/gsbug.templates" and press RETURN.  Keep
  535. trying until you get it right - it does work (watch out for typos, etc).
  536.  
  537. To view a piece of memory with a template, simply determine the starting
  538. address of the template.  The starting address can be found in a number of
  539. ways - you can dereference a pointer that you just pushed on the stack, etc.
  540. Then, type an underscore, the type of structure you want used, a blank space,
  541. and the starting address (don't forget the bank).  (i.e.:  if you know you
  542. have a graf port starting at location 06/15E4, then type:  "_grafport 06/15E4"
  543. and press RETURN.
  544.  
  545. To use the built-in template help system that Jim came up with (thanks Jim!),
  546. just type: "_template 0" and press return.  This will give you a list of all
  547. the categories of help you can get more info on (such as ADB, FONTS, etc).
  548. The categories are grouped by toolbox manager.  To get details on a particular
  549. toolbox manager's tool calls, type "_toolmgrname 0" and press RETURN
  550. (replace "_toolmgrname" with the name of any tool manager - lead with an
  551. underscore or it won't work).  (i.e.: "_quickdraw 0" for details on QuickDraw
  552. data structures)  For more details, read the separate documentation file on
  553. using the templates.
  554.  
  555. If you want to create your own custom templates, then read the GSBug manual
  556. (pages 86-88) or decipher the templates in the GSBug.Templates file.  To
  557. unload the templates (and free up the memory they're eating), type "killtemp"
  558. and press RETURN from GSBug's command line.
  559.  
  560.  
  561. The New Stuff:
  562.  
  563. As if all of this weren't reason enough to use GSBug, the man behind this
  564. jewel added several more reasons (he calls them features).  All of these are
  565. fake tool calls that the debugger sees, intercepts, and acts on.
  566.  
  567. The new calls are SetMileStone, DebugStr, DebugVersion, and DebugStatus.
  568. The two most important ones (in my opinion) are "SetMileStone" and "DebugStr".
  569.  
  570. SetMileStone simply changes the debugger's copyright message to be a string of
  571. your choice and lets your app keep running.  If you're having a problem
  572. figuring out where your code was last at before it jumped off into the weeds,
  573. then sprinkle SetMileStone calls into your source code (with different strings
  574. on each, of course).  Then, when your app chokes and dies, you'll be presented
  575. with the text from the last SetMileStone that was executed.
  576.  
  577. DebugStr works like SetMileStone (i.e.: changes the copyright string
  578. to something with info about your application) except it dumps you immediately
  579. into GSBug.  This is a little more work than Cheap Trick #1, but you can line
  580. up your source easier (since you'll have the debug string's message to guide
  581. you).
  582.  
  583. DebugVersion and DebugStatus act just like normal version and status calls for
  584. regular tool sets - they simply allow you to verify whether GSBug is running
  585. and if so, what version of the debugger is running before you try to make any
  586. debugger tool calls.
  587.  
  588. The tool numbers and parameter lists for these calls are:
  589.  
  590. Name            Tool #  Parameter (returns)
  591. --------------  ------  ---------------------------------------------------
  592. DebugStatus     $06FF   (non-zero = true, ToolLocator error it not loaded)
  593. DebugStr        $09FF   pointer to Pascal-style string
  594. DebugVersion    $04FF   ($159F for v.1.5B9)
  595. SetMileStone    $0AFF   pointer to Pascal-style string
  596.  
  597.  
  598. Cheap (and short) Trick #6:
  599.  
  600. If you get really fancy, you can build the strings for DebugStr and
  601. SetMileStone on the fly and imbed the values of key variables into them to
  602. further simplify locating bugs.
  603.  
  604.  
  605. Calling all Debuggers:
  606.  
  607. Do _NOT_ leave calls to these debugger tools in your software when you ship it
  608. to customers!  Why?  Because making these calls on a system that doesn't have
  609. GSBug installed makes a real mess...
  610.  
  611.  
  612. Want More Info?
  613.  
  614. Contact APDA and order the full package (you have a newer version of GSBug
  615. with this file, but APDA has the full manual).  Order it by calling APDA
  616. (1-800-282-2732) and asking for part #A0037LL/A (the price is $30).  Due to recent changes in APDA, you no longer need to be a member before you can order this product.
  617.